#pragma once
#include "gtest/gtest.h"
#include "DataStructure/Input/Property/BeamSectionStandardTypes.h"
#include "../Interface/BarSectionFormulaCalculatorFactory.h"
#include "../Bar/BarSectionFormulaCalculator.h"

using SG::Algebra::Point;
using namespace SG::DataStructure::FEM;
using SG::FEMSolver::Element::BarSectionFormulaCalculatorFactory;
using SG::FEMSolver::Element::BarSectionFormulaCalculator;

// 将 BarSectionFormulaCalculatorFactory 生成对象测试放置在具体截面属性计算中
TEST (BarSectionFormulaCalculatorFactoryTest, BarSectionCalculatorCreate)
{
    // Test data
    auto calculatorPtr = BarSectionFormulaCalculatorFactory::Create (BeamSectionStandardTypes::BEAMSECTYPE_BAR);
    auto barCalculatorPtr = dynamic_cast<BarSectionFormulaCalculator*> (calculatorPtr.get ());

    // Check
    ASSERT_TRUE (nullptr != barCalculatorPtr);
}

// Bar 截面属性计算测试
TEST (BarSectionFormulaCalculatorTest, BarSectionDIM1gtDIM2)
{
    // Input data
    PBARLData section;
    section.m_id  = 2;
    section.m_mId = 3;
    section.SetGroup ("MSCBML0");
    section.SetBeamSectionStandardTypes (BeamSectionStandardTypes::BEAMSECTYPE_BAR);
    section.m_dimension = {3.5, 2.0};
    section.m_nsm = 10.0;

    // Test data
    BarSectionFormulaCalculator calculator;
    PBARData propertyTest;
    Point centroidTest;
    calculator.Compute (section, _OUT propertyTest, _OUT centroidTest);

    // Target data
    PBARData propertyTarget;
    propertyTarget.m_id  = 2;
    propertyTarget.m_mId = 3;
    propertyTarget.m_A   = 7.0;
    propertyTarget.m_I1  = 2.333333;
    propertyTarget.m_I2  = 7.145833;
    propertyTarget.m_I12 = 0.0;
    propertyTarget.m_J   = 6.003188;
    propertyTarget.m_K1  = 0.8333333;
    propertyTarget.m_K2  = 0.8333333;
    propertyTarget.m_NSM = 10.0;
    propertyTarget.m_FE  = 0.0;
    propertyTarget.SetStressPoints ({1.0, 1.75, -1.0, 1.75, -1.0, -1.75, 1.0, -1.75});
    Point centroidTarget;

    // Check
    ASSERT_TRUE (propertyTarget == propertyTest);
    ASSERT_TRUE (centroidTarget == centroidTest);
}

TEST (BarSectionFormulaCalculatorTest, BarSectionDIM1ltDIM2)
{
    // Input data
    PBARLData section;
    section.m_id  = 2;
    section.m_mId = 3;
    section.SetGroup ("MSCBML0");
    section.SetBeamSectionStandardTypes (BeamSectionStandardTypes::BEAMSECTYPE_BAR);
    section.m_dimension = {2.0, 3.5};
    section.m_nsm = 10.0;

    // Test data
    BarSectionFormulaCalculator calculator;
    PBARData propertyTest;
    Point centroidTest;
    calculator.Compute (section, _OUT propertyTest, _OUT centroidTest);

    // Target data
    PBARData propertyTarget;
    propertyTarget.m_id  = 2;
    propertyTarget.m_mId = 3;
    propertyTarget.m_A   = 7.0;
    propertyTarget.m_I1  = 7.145833;
    propertyTarget.m_I2  = 2.333333;
    propertyTarget.m_I12 = 0.0;
    propertyTarget.m_J   = 6.003188;
    propertyTarget.m_K1  = 0.8333333;
    propertyTarget.m_K2  = 0.8333333;
    propertyTarget.m_NSM = 10.0;
    propertyTarget.m_FE  = 0.0;
    propertyTarget.SetStressPoints ({1.75, 1.0, -1.75, 1.0, -1.75, -1.0, 1.75, -1.0});
    Point centroidTarget;

    // Check
    ASSERT_TRUE (propertyTarget == propertyTest);
    ASSERT_TRUE (centroidTarget == centroidTest);
}